<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能工作计划作息规划表应用 - ERNIE-4.5-0.3B</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            color: white;
            margin-bottom: 30px;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .tech-badge {
            display: inline-block;
            background: rgba(255,255,255,0.2);
            padding: 5px 15px;
            border-radius: 20px;
            margin: 5px;
            font-size: 0.9rem;
        }

        .main-content {
            display: grid;
            grid-template-columns: 1fr 2fr;
            gap: 30px;
            margin-top: 30px;
        }

        .sidebar {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            height: fit-content;
        }

        .content-area {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }

        .form-group input,
        .form-group select,
        .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s;
        }

        .form-group input:focus,
        .form-group select:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: #667eea;
        }

        .checkbox-group {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
            background: #f8f9fa;
            padding: 8px 12px;
            border-radius: 20px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .checkbox-item:hover {
            background: #e9ecef;
        }

        .checkbox-item input {
            margin-right: 8px;
            width: auto;
        }

        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            transition: transform 0.3s, box-shadow 0.3s;
            margin: 10px 5px;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .btn-secondary {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            color: #333;
        }

        .schedule-display {
            margin-top: 30px;
        }

        .schedule-item {
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            padding: 15px;
            margin-bottom: 15px;
            border-radius: 8px;
            transition: transform 0.3s;
        }

        .schedule-item:hover {
            transform: translateX(5px);
        }

        .schedule-time {
            font-weight: bold;
            color: #667eea;
            font-size: 1.1rem;
        }

        .schedule-activity {
            font-size: 1.2rem;
            margin: 5px 0;
        }

        .schedule-tips {
            color: #666;
            font-style: italic;
        }

        .priority-high {
            border-left-color: #e74c3c;
        }

        .priority-medium {
            border-left-color: #f39c12;
        }

        .priority-low {
            border-left-color: #27ae60;
        }

        .tips-section {
            margin-top: 30px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }

        .tips-card {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }

        .tips-card h3 {
            color: #333;
            margin-bottom: 15px;
            font-size: 1.3rem;
        }

        .tips-list {
            list-style: none;
        }

        .tips-list li {
            background: rgba(255,255,255,0.7);
            padding: 10px;
            margin-bottom: 8px;
            border-radius: 8px;
            border-left: 3px solid #667eea;
        }

        .loading {
            text-align: center;
            padding: 40px;
        }

        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #667eea;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .analysis-section {
            margin-top: 30px;
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
            padding: 25px;
            border-radius: 15px;
        }

        .score-display {
            text-align: center;
            margin-bottom: 20px;
        }

        .score-circle {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background: conic-gradient(#667eea 0deg, #667eea var(--score-deg), #e1e5e9 var(--score-deg), #e1e5e9 360deg);
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 15px;
            position: relative;
        }

        .score-circle::before {
            content: '';
            width: 70px;
            height: 70px;
            background: white;
            border-radius: 50%;
            position: absolute;
        }

        .score-text {
            position: relative;
            z-index: 1;
            font-size: 1.5rem;
            font-weight: bold;
            color: #333;
        }

        @media (max-width: 768px) {
            .main-content {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 2rem;
            }
            
            .tips-section {
                grid-template-columns: 1fr;
            }
        }

        .dataset-info {
            background: rgba(255,255,255,0.1);
            padding: 15px;
            border-radius: 10px;
            margin-top: 20px;
            color: white;
        }

        .dataset-info h4 {
            margin-bottom: 10px;
            color: #ffd700;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🕐 智能工作计划作息规划表应用</h1>
            <p>基于ERNIE-4.5-0.3B-Paddle模型 + 智源Infinity-Instruct数据集</p>
            <div>
                <span class="tech-badge">🧠 ERNIE-4.5-0.3B</span>
                <span class="tech-badge">📊 智源研究院</span>
                <span class="tech-badge">🏆 AI应用大赛</span>
                <span class="tech-badge">⚡ PaddlePaddle</span>
            </div>
            
            <div class="dataset-info">
                <h4>🔬 技术架构</h4>
                <p>• 模型层：百度文心大模型ERNIE-4.5-0.3B-Paddle</p>
                <p>• 知识层：智源研究院Infinity-Instruct数据集</p>
                <p>• 应用层：智能作息规划与时间管理系统</p>
            </div>
        </div>

        <div class="main-content">
            <div class="sidebar">
                <h2>📝 个人信息设置</h2>
                <form id="userProfileForm">
                    <div class="form-group">
                        <label for="userName">姓名</label>
                        <input type="text" id="userName" name="name" placeholder="请输入您的姓名" required>
                    </div>

                    <div class="form-group">
                        <label for="wakeTime">起床时间</label>
                        <input type="time" id="wakeTime" name="wake_time" value="07:00" required>
                    </div>

                    <div class="form-group">
                        <label for="sleepTime">睡觉时间</label>
                        <input type="time" id="sleepTime" name="sleep_time" value="23:00" required>
                    </div>

                    <div class="form-group">
                        <label for="workType">主要工作类型</label>
                        <select id="workType" name="work_type" required>
                            <option value="创意工作">创意工作</option>
                            <option value="分析工作">分析工作</option>
                            <option value="沟通协调">沟通协调</option>
                            <option value="学习培训">学习培训</option>
                            <option value="体力劳动">体力劳动</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label>健康目标</label>
                        <div class="checkbox-group">
                            <div class="checkbox-item">
                                <input type="checkbox" id="goal1" name="health_goals" value="减肥">
                                <label for="goal1">减肥</label>
                            </div>
                            <div class="checkbox-item">
                                <input type="checkbox" id="goal2" name="health_goals" value="改善睡眠">
                                <label for="goal2">改善睡眠</label>
                            </div>
                            <div class="checkbox-item">
                                <input type="checkbox" id="goal3" name="health_goals" value="提高专注力">
                                <label for="goal3">提高专注力</label>
                            </div>
                            <div class="checkbox-item">
                                <input type="checkbox" id="goal4" name="health_goals" value="增强体质">
                                <label for="goal4">增强体质</label>
                            </div>
                        </div>
                    </div>

                    <button type="submit" class="btn">🚀 生成智能作息规划</button>
                    <button type="button" class="btn btn-secondary" onclick="getRecommendations()">💡 获取AI建议</button>
                </form>

                <div style="margin-top: 30px;">
                    <h3>📊 作息效果反馈</h3>
                    <form id="feedbackForm">
                        <div class="form-group">
                            <label>精力状态 (1-5分)</label>
                            <input type="range" id="energyLevel" name="energy_level" min="1" max="5" value="3">
                            <span id="energyValue">3</span>
                        </div>
                        <div class="form-group">
                            <label>工作效率 (1-5分)</label>
                            <input type="range" id="productivity" name="productivity" min="1" max="5" value="3">
                            <span id="productivityValue">3</span>
                        </div>
                        <div class="form-group">
                            <label>睡眠质量 (1-5分)</label>
                            <input type="range" id="sleepQuality" name="sleep_quality" min="1" max="5" value="3">
                            <span id="sleepValue">3</span>
                        </div>
                        <button type="submit" class="btn">📈 分析效果</button>
                    </form>
                </div>
            </div>

            <div class="content-area">
                <div id="scheduleDisplay">
                    <h2>📅 您的智能作息规划</h2>
                    <p style="color: #666; margin-bottom: 20px;">请填写左侧个人信息，生成专属的智能作息规划表</p>
                    
                    <div style="text-align: center; padding: 40px;">
                        <div style="font-size: 4rem; margin-bottom: 20px;">🕐</div>
                        <h3>等待生成个性化作息规划...</h3>
                        <p>基于ERNIE-4.5-0.3B模型和智源数据集的AI智能分析</p>
                    </div>
                </div>

                <div id="analysisDisplay" style="display: none;">
                    <h2>📊 作息效果分析</h2>
                    <div id="analysisContent"></div>
                </div>

                <div class="tips-section" id="tipsSection" style="display: none;">
                    <div class="tips-card">
                        <h3>🏥 健康建议</h3>
                        <ul class="tips-list" id="healthTips"></ul>
                    </div>
                    <div class="tips-card">
                        <h3>⚡ 效率建议</h3>
                        <ul class="tips-list" id="productivityTips"></ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 更新滑块显示值
        document.getElementById('energyLevel').oninput = function() {
            document.getElementById('energyValue').textContent = this.value;
        }
        document.getElementById('productivity').oninput = function() {
            document.getElementById('productivityValue').textContent = this.value;
        }
        document.getElementById('sleepQuality').oninput = function() {
            document.getElementById('sleepValue').textContent = this.value;
        }

        // 生成作息规划
        document.getElementById('userProfileForm').onsubmit = async function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const userData = {};
            
            // 处理普通字段
            for (let [key, value] of formData.entries()) {
                if (key === 'health_goals') {
                    if (!userData[key]) userData[key] = [];
                    userData[key].push(value);
                } else {
                    userData[key] = value;
                }
            }

            showLoading();

            try {
                const response = await fetch('/api/generate_schedule', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(userData)
                });

                const result = await response.json();
                
                if (result.success) {
                    displaySchedule(result.schedule);
                } else {
                    alert('生成失败: ' + result.message);
                }
            } catch (error) {
                alert('网络错误: ' + error.message);
            }
        };

        // 效果分析
        document.getElementById('feedbackForm').onsubmit = async function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const feedbackData = {};
            
            for (let [key, value] of formData.entries()) {
                feedbackData[key] = parseInt(value);
            }

            try {
                const response = await fetch('/api/analyze_effectiveness', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(feedbackData)
                });

                const result = await response.json();
                
                if (result.success) {
                    displayAnalysis(result.analysis);
                } else {
                    alert('分析失败: ' + result.message);
                }
            } catch (error) {
                alert('网络错误: ' + error.message);
            }
        };

        function showLoading() {
            document.getElementById('scheduleDisplay').innerHTML = `
                <div class="loading">
                    <div class="spinner"></div>
                    <h3>🧠 AI正在分析您的需求...</h3>
                    <p>基于ERNIE-4.5-0.3B模型和智源数据集生成个性化建议</p>
                </div>
            `;
        }

        function displaySchedule(schedule) {
            let html = `
                <h2>📅 您的智能作息规划</h2>
                <div style="background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); padding: 20px; border-radius: 15px; margin-bottom: 20px;">
                    <h3>⏰ 基本时间安排</h3>
                    <p><strong>起床时间:</strong> ${schedule.wake_time}</p>
                    <p><strong>睡觉时间:</strong> ${schedule.sleep_time}</p>
                </div>
                <div class="schedule-display">
            `;

            schedule.daily_plan.forEach(item => {
                const priorityClass = `priority-${item.priority === '高' ? 'high' : item.priority === '中' ? 'medium' : 'low'}`;
                html += `
                    <div class="schedule-item ${priorityClass}">
                        <div class="schedule-time">${item.time}</div>
                        <div class="schedule-activity">${item.activity} (${item.period})</div>
                        <div class="schedule-tips">${item.tips}</div>
                    </div>
                `;
            });

            html += '</div>';

            document.getElementById('scheduleDisplay').innerHTML = html;

            // 显示建议
            if (schedule.health_tips || schedule.productivity_tips) {
                displayTips(schedule.health_tips, schedule.productivity_tips);
            }
        }

        function displayTips(healthTips, productivityTips) {
            document.getElementById('tipsSection').style.display = 'grid';
            
            if (healthTips) {
                const healthList = document.getElementById('healthTips');
                healthList.innerHTML = '';
                healthTips.forEach(tip => {
                    const li = document.createElement('li');
                    li.textContent = tip;
                    healthList.appendChild(li);
                });
            }

            if (productivityTips) {
                const productivityList = document.getElementById('productivityTips');
                productivityList.innerHTML = '';
                productivityTips.forEach(tip => {
                    const li = document.createElement('li');
                    li.textContent = tip;
                    productivityList.appendChild(li);
                });
            }
        }

        function displayAnalysis(analysis) {
            const scoreDeg = (analysis.overall_score / 100) * 360;
            
            let html = `
                <div class="analysis-section">
                    <div class="score-display">
                        <div class="score-circle" style="--score-deg: ${scoreDeg}deg;">
                            <div class="score-text">${analysis.overall_score}</div>
                        </div>
                        <h3>综合评分</h3>
                    </div>
            `;

            if (analysis.strengths.length > 0) {
                html += `
                    <div style="margin-bottom: 20px;">
                        <h4>✅ 优势方面</h4>
                        <ul>
                            ${analysis.strengths.map(s => `<li>${s}</li>`).join('')}
                        </ul>
                    </div>
                `;
            }

            if (analysis.improvements.length > 0) {
                html += `
                    <div style="margin-bottom: 20px;">
                        <h4>🔧 改进建议</h4>
                        <ul>
                            ${analysis.improvements.map(i => `<li>${i}</li>`).join('')}
                        </ul>
                    </div>
                `;
            }

            if (analysis.recommendations.length > 0) {
                html += `
                    <div>
                        <h4>💡 AI智能建议</h4>
                        <ul>
                            ${analysis.recommendations.map(r => `<li>${r}</li>`).join('')}
                        </ul>
                    </div>
                `;
            }

            html += '</div>';

            document.getElementById('analysisContent').innerHTML = html;
            document.getElementById('analysisDisplay').style.display = 'block';
        }

        async function getRecommendations() {
            try {
                const response = await fetch('/api/get_recommendations');
                const result = await response.json();
                
                if (result.success) {
                    displayTips(result.recommendations.health_tips, result.recommendations.productivity_tips);
                } else {
                    alert('获取建议失败: ' + result.message);
                }
            } catch (error) {
                alert('网络错误: ' + error.message);
            }
        }

        // 页面加载完成后的初始化
        window.onload = function() {
            console.log('🚀 智能作息规划应用已启动');
            console.log('📊 基于ERNIE-4.5-0.3B-Paddle模型');
            console.log('🧠 集成智源Infinity-Instruct数据集');
        };
    </script>
</body>
</html>